<template>
  <el-card>
    <!-- inline是控制的表单在一行显示 -->
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
          v-model="categoryStore.c1Id"
          @change="handler"
          :disabled="scene ? true : false"
        >
          <el-option
            v-for="(c1, index) in categoryStore.c1Arr"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="categoryStore.c2Id"
          @change="handler1"
          :disabled="scene ? true : false"
        >
          <el-option
            v-for="(c2, index) in categoryStore.c2Arr"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          v-model="categoryStore.c3Id"
          :disabled="scene ? true : false"
        >
          <el-option
            v-for="(c3, index) in categoryStore.c3Arr"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts" setup>
import { onMounted, onUnmounted } from "vue";
import useCategoryStore from "@/stores/catrgory";

// 创建仓库的实例化对象
const categoryStore = useCategoryStore();

// 生命周期的挂载
onMounted(() => {
  useCategoryStore().getC1();
});
const handler = () => {
  // 清空二级和三级的相关的数据
  categoryStore.c2Id = "";
  categoryStore.c3Arr = [];
  categoryStore.c3Id = "";
  categoryStore.getC2();
};
const handler1 = () => {
  // 清空三级的数据
  categoryStore.c3Id = "";
  // 发送请求获取数据
  categoryStore.getC3();
};
onUnmounted(() => {
  // 重置仓库:数据清除
  categoryStore.$reset();
});
defineProps(["scene"]);
</script>
